﻿using MiniFox.Web;
using MiniFox.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Mime;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http.Headers;

namespace MiniFox.Net.Models
{
    /// <summary>
    /// 
    /// </summary>
    public class WebObjectRequest<T> : WebMessageRequestBase
    {
        T _data;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        public WebObjectRequest(T data) : this(data, null)
        {
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        /// <param name="query"></param>
        public WebObjectRequest(T data, object query) : this(data, query, null)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        /// <param name="query"></param>
        /// <param name="headers"></param>
        public WebObjectRequest(T data, object query, object headers) : this(HttpMethod.Post, data, query, headers)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="method"></param>
        /// <param name="data"></param>
        public WebObjectRequest(HttpMethod method, T data) : this(method, data, null)
        {
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="method"></param>
        /// <param name="data"></param>
        /// <param name="query"></param>
        public WebObjectRequest(HttpMethod method, T data,  object query) : this(method, data, query, null)
        {

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="method"></param>
        /// <param name="data"></param>
        /// <param name="query"></param>
        /// <param name="headers"></param>
        public WebObjectRequest(HttpMethod method, T data, object query, object headers) : base(method, query, headers)
        {
            _data = data;
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual T Data
        {
            get { return this._data; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected internal override HttpContent CreateHttpContent()
        {
            string json = this.Data.ToJsonString();
            var httpContent = new StringContent(json);
            httpContent.Headers.ContentType = new MediaTypeHeaderValue(WebUtil.MIME_TYPE_JSON);
            return httpContent;
        }
    }

}
